package com.tgit.sso.client.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.tgit.sso.core.conf.SsoConf;
import com.tgit.sso.core.conf.SsoFilter;
import com.tgit.sso.core.util.JedisUtil;
/**
 * 
 * @author 范再军
 * 2018年9月18日
 * 配置三个地址：
 * sso服务端地址，redis地址，sso登出地址
 * 
 */
@Configuration
public class SsoConfig {

    @Value("${tgit.sso.server}")
    private String ssoServer;

    @Value("${tgit.sso.logout.path}")
    private String ssoLogoutPath;

    @Value("${tgit.sso.client.server}")
    private String clientServer;
    
    @Value("${tgit.sso.redis.address}")
    private String ssoRedisAddress;
    
    @Value("${tgit.sso.flag}")
    private String ssoFlag;
    
    @Value("${tgit.sso.connect.url}")
    private String ssoConnectUrl;

    @Bean
    public FilterRegistrationBean tgitSsoFilterRegistration() {

        //过滤器
        FilterRegistrationBean registration = new FilterRegistrationBean();

        registration.setName("SsoFilter");
        registration.setOrder(1);
        registration.addUrlPatterns("/*");
        registration.setFilter(new SsoFilter());
        registration.addInitParameter(SsoConf.SSO_SERVER, ssoServer);
        registration.addInitParameter(SsoConf.SSO_LOGOUT_PATH, ssoLogoutPath);
        registration.addInitParameter(SsoConf.CLIENT_SERVER, clientServer);
        registration.addInitParameter(SsoConf.REDIS_ADDRESS, ssoRedisAddress);
        registration.addInitParameter(SsoConf.SSO_FLAG, ssoFlag);
        registration.addInitParameter(SsoConf.SSO_CONNECT_URL, ssoConnectUrl);

        return registration;
    }
}
